package com.example.chapter11;


import java.util.function.Predicate;

/**
 * 11.2.6.函数组合
 */
public class Demo04 {


    public static void  and(){
        //1.and（）
        Predicate<String> startsWithA = (text) -> text.startsWith("A");
        Predicate<String> endsWithX   = (text) -> text.endsWith("x");

        Predicate<String> composed = startsWithA.and(endsWithX);

        String input = "A hardworking person must relax";
        boolean result = composed.test(input);
        System.out.println(result);
    }


    public static void or(){
        //2.or()
        Predicate<String> startsWithA = (text) -> text.startsWith("A");
        Predicate<String> endsWithX   = (text) -> text.endsWith("x");

        Predicate<String> composed = startsWithA.or(endsWithX);

        String input = "A hardworking person must relax sometimes";
        boolean result = composed.test(input);
        System.out.println(result);
    }


    public static void main(String[] args) {
        Predicate<String> startsWithA = (text) -> text.startsWith("A");
        Predicate<String> endsWithX   = (text) -> text.endsWith("x");

        Predicate<String> startsWithAAndEndsWithX =
                (text) -> startsWithA.test(text) && endsWithX.test(text);

        String  input  = "A hardworking person must relax";
        boolean result = startsWithAAndEndsWithX.test(input);
        System.out.println(result);

        and();

        or();

    }
}
